package com.ruoyi.system.controller;

import java.util.List;


import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.SysChecklist;
import com.ruoyi.system.domain.SysPrescriptionlist;

import com.ruoyi.system.domain.SysVisitrecord;
import com.ruoyi.system.service.ISysVisitrecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;


/**
 * 就诊信息Controller
 * 
 * @author ruoyi
 * @date 2024-06-29
 */
@RestController
@RequestMapping("/visit/visitRecord")
public class SysVisitrecordController extends BaseController
{
    @Autowired
    private ISysVisitrecordService sysVisitrecordService;

    /**
     * 查询就诊信息列表
     */
    @PreAuthorize("@ss.hasPermi('visit:visitRecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysVisitrecord sysVisitrecord)
    {
        startPage();
        List<SysVisitrecord> list = sysVisitrecordService.selectSysVisitrecordList(sysVisitrecord);
        return getDataTable(list);
    }

    /**
     * 导出就诊信息列表
     */
    @PreAuthorize("@ss.hasPermi('visit:visitRecord:export')")
    @Log(title = "就诊信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysVisitrecord sysVisitrecord)
    {
        List<SysVisitrecord> list = sysVisitrecordService.selectSysVisitrecordList(sysVisitrecord);
        ExcelUtil<SysVisitrecord> util = new ExcelUtil<SysVisitrecord>(SysVisitrecord.class);
        util.exportExcel(response, list, "就诊信息数据");
    }

    /**
     * 获取就诊信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('visit:visitRecord:query')")
    @GetMapping(value = "/{visitId}")
    public AjaxResult getInfo(@PathVariable("visitId") Long visitId)
    {
        return success(sysVisitrecordService.selectSysVisitrecordByVisitId(visitId));
    }

    /**
     * 新增就诊信息
     */
    @PreAuthorize("@ss.hasPermi('visit:visitRecord:add')")
    @Log(title = "就诊信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysVisitrecord sysVisitrecord)
    {
        return toAjax(sysVisitrecordService.insertSysVisitrecord(sysVisitrecord));
    }

    /**
     * 修改就诊信息
     */
    @PreAuthorize("@ss.hasPermi('visit:visitRecord:edit')")
    @Log(title = "就诊信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysVisitrecord sysVisitrecord)
    {
        return toAjax(sysVisitrecordService.updateSysVisitrecord(sysVisitrecord));
    }

    /**
     * 删除就诊信息
     */
    @PreAuthorize("@ss.hasPermi('visit:visitRecord:remove')")
    @Log(title = "就诊信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{visitIds}")
    public AjaxResult remove(@PathVariable Long[] visitIds)
    {
        return toAjax(sysVisitrecordService.deleteSysVisitrecordByVisitIds(visitIds));
    }

    /**
     * 增加检查订单
     */
    @PreAuthorize("@ss.hasPermi('visit:visitRecord:addCheck')")
    @Log(title = "检查订单", businessType = BusinessType.INSERT)
    @PostMapping("/check")
    public AjaxResult addCheck(@RequestBody SysChecklist sysChecklist)
    {
        //System.out.println("增加订单" + sysChecklist);
        return toAjax(sysVisitrecordService.insertSysChecklist(sysChecklist));
    }

    @PreAuthorize("@ss.hasPermi('visit:visitRecord:addPrescription')")
    @Log(title = "检查订单", businessType = BusinessType.INSERT)
    @PostMapping("/prescription")
    public AjaxResult addPrescription(@RequestBody SysPrescriptionlist sysPrescriptionlist)
    {
        System.out.println("增加处方" + sysPrescriptionlist);
        return toAjax(sysVisitrecordService.insertSysPrescriptionlist(sysPrescriptionlist));
    }
}
